<?php

class Helper{
	private static $fp = null;
	
	/*
	 * 记录日志
	 */
	public static function log($log) {
		if(null === self::$fp) {
			$logFile = sprintf('%s/logs/sms.%s.log', DIR, date('Ymd'));
			self::$fp = fopen($logFile, 'a+');
		}
		
		fwrite(self::$fp, $log);
		echo $log;
	}
	
	/*
	 * 随机串 模拟 js rand
	 */
	public static function randNum() {
		return '0.'.rand(10000001, 90000009).rand(10000001, 90000009);
	}
	
	/*
	 * 清理
	 */
	public static function clear() {
		self::$fp && fclose(self::$fp);
	}
	
	/*
	 * 解析 外部输入
	 */
	public static function parseArgv($argv) {
		$args = array();
		
		if(!empty($argv) && is_array($argv)) {
			foreach($argv as $item) {
				if(preg_match("#^--(\w+)\=(.*?)$#", $item, $arr)) {
					$args[$arr[1]] = $arr[2];
				}
			}
		}
		
		!empty($_GET) && $args = array_merge($args, $_GET);
		return $args;
	}
	
	/*
	 * 毫秒
	 */
	public static function millisecond() {
		return floor(microtime(true)*100);
	}
}